package com.mldong.modules.cms.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mldong.base.CommonPage;
import com.mldong.modules.cms.dto.PositionPageParam;
import com.mldong.modules.cms.dto.PositionParam;
import com.mldong.modules.cms.vo.PositionVO;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import com.mldong.modules.cms.entity.Position;
import com.mldong.modules.cms.mapper.PositionMapper;
import com.mldong.modules.cms.service.PositionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 推荐位 服务实现类
 * </p>
 *
 * @author mldong
 * @since 2022-10-23
 */
@Service
public class PositionServiceImpl extends ServiceImpl<PositionMapper, Position> implements PositionService {
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(PositionParam param) {
        param.setId(null);
        Position Position = new Position();
        BeanUtil.copyProperties(param, Position);
        return super.save(Position);
    }

    @Override
    public boolean update(PositionParam param) {
        Position Position = new Position();
        BeanUtil.copyProperties(param, Position);
        return super.updateById(Position);
    }

    @Override
    public CommonPage<PositionVO> page(PositionPageParam param) {
        IPage<PositionVO> page = param.buildMpPage();
        QueryWrapper queryWrapper = param.buildQueryWrapper();
        queryWrapper.eq("t.is_deleted",0);
        List<PositionVO> list = baseMapper.selectCustom(page, queryWrapper);
        page.setRecords(list);
        return CommonPage.toPage(page);
    }
    @Override
    public PositionVO findById(Long id) {
        return baseMapper.findById(id);
    }
}
